package com.mxpio.erp.common.quality.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpioframework.jpa.annotation.DictAble;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


@Data
@Entity
@Table(name = "v_mb_erp_quality_ib_detail")
@Schema(description="检验记录报表")
@NoArgsConstructor
@AllArgsConstructor
public class VInspectionBillRecord implements DictAble , Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "id")
    @Schema(description = "id")
    private String id;

    @Column(name = "order_biz_no_")
    @Schema(description = "订单号")
    private String orderBizNo;

    @Column(name = "ORIGIN_BIZ_TYPE_")
    @Schema(description = "来源单类型")
    @Dict(dicCode="ERP_QUAL_ORIGIN_BIZ_TYPE")
    private String originBizType;

    @Column(name = "ORDER_STATUS_")
    @Schema(description = "订单状态")
    @Dict(dicCode = "ERP_COMMON_ORDER_STATUS")
    private String orderStatus;

    @Column(name = "ITEM_CODE_")
    @Schema(description = "物料代码")
    private String itemCode;

    @Column(name = "ITEM_NAME_")
    @Schema(description = "物料名称")
    private String itemName ;

    @Column(name = "DRAWING_NO_")
    @Schema(description = "图号")
    private String drawingNo;

    @Column(name = "order_line_quantity_")
    @Schema(description = "订单数量")
    private BigDecimal orderLineQuantity;

    @Column(name = "qo_notice_no_")
    @Schema(description = "验收单号")
    private String qoNoticeNo;

    @Column(name = "APPLY_ORG_TYPE_")
    @Schema(description = "交检组织类别")
    @Dict(dicCode="ERP_QUAL_APPLY_ORG_TYPE")
    private String applyOrgType;

    @Column(name = "APPLY_ORG_NAME_")
    @Schema(description = "交检组织名称")
    private String applyOrgName;

    @Column(name = "APPLY_ORG_CODE_")
    @Schema(description = "交检组织编码")
    private String applyOrgCode;

    @Column(name = "CREATE_TIME")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(description = "交检时间")
    private Date createTime;

    @Column(name = "QUANTITY_")
    @Schema(description = "交检数量")//验收单确认数量
    private BigDecimal quantity;

    @Column(name = "ib_biz_no_")
    @Schema(description = "质检单号")
    private String ibBizNo;

    @Column(name = "INSPECTION_START_TIME_")
    @Schema(description = "检验开始时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date inspectionStartTime;

    @Column(name = "CHECK_QUANTITY_")
    @Schema(description = "抽检数量")
    private BigDecimal checkQuantity;

    @Column(name = "check_rate_")
    @Schema(description = "抽检比例（%）")
    private BigDecimal checkRate;

    @Column(name = "UNQUALIFIED_QUANTITY_")
    @Schema(description = "不合格数量")
    private BigDecimal unqualifiedQuantity;

    @Column(name = "pass_rate_")
    @Schema(description = "交检合格率（%）")
    private BigDecimal passRate;

    @Column(name = "INSPECTOR_")
    @Schema(description = "检验员")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String inspector;

    @Column(name = "last_stock_time_")
    @Schema(description = "最后入库时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date lastStockTime;

    @Column(name = "stock_quantity_")
    @Schema(description = "入库数量")
    private BigDecimal stockQuantity;

    @Column(name = "stock_man_")
    @Schema(description = "入库人")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String stockMan;

    @Column(name = "UNQUALIFIED_TYPE_")
    @Schema(description = "不合格原因类型")
    @Dict(dicCode = "ERP_QUAL_UNQUALIFIED_TYPE")
    private String unqualifiedType;

    @Column(name = "UNQUALIFIED_DESC_")
    @Schema(description = "不合格描述")
    private String unqualifiedDesc;

    @Column(name = "MEMO_",columnDefinition="TEXT")
    @Schema(description = "备注")
    private String memo;
    @Transient
    private Map<String, String> textMap;

    public String putText(String key, String value) {
        if (textMap == null) {
            textMap = new HashMap<>();
        }
        return textMap.put(key, value);
    }

}
